package app.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import sun.security.util.Password;

/** 
 * 
 * @author Nachman Mathieu
 * @author David Gianorio
 * @author Faton Alia
 * 
 * This class will be used to store all basic information about users */
@Entity
@Table(name="MEMBER")
public class Member {

	@Id
	@GeneratedValue
	private Long id;
	
	/* This set will be instanciated for each user and will store all downloaded applications (for history) */
	@OneToMany
	@JoinTable(name="USER_APPLICATION", joinColumns =@JoinColumn(name="USER_ID"),
				inverseJoinColumns = @JoinColumn(name="APPLICATION_ID"))
	private Set<Application> downloadedApplications = new HashSet<Application>();
	
	private String companyName;
	private String firstName;
	private String lastName;
	private Date birthDate;
	private String addrStreet;
	private String addrNumber;
	private String addrPostCode;
	private String addrCity;
	private String country;
	private String email;
	private String telephone;
	private Date inscriptionDate;
	private String password;
	private String username;
	
	// Will store developper Technical Skills and comment
	private String developerSkills;
	private String developerComment;
	
	// Counter to count number of upload of a developer
	private int countNumberOfUploads;
	
	@Column(nullable= false)
	@Enumerated(EnumType.STRING)
	private Role role; 
	
	public Member(String companyName, String email, Role role, String username, String password) {

		this.companyName = companyName;
		this.email = email;
		this.role = role;
		this.username = username;
		this.password = password;
	}
	
	public Member(){}
	
	/////////////////////////////////////////////////////////////////
	/////////////////////////// Methods /////////////////////////////
	/////////////////////////////////////////////////////////////////
	
	public void addDownloadedApplicationToSet(Application app) {
		downloadedApplications.add(app);
	}

	/////////////////////////////////////////////////////////////////
	/////////////////////// Generated Code //////////////////////////
	/////////////////////////////////////////////////////////////////
	
	// Getters
	public Long getId() {
		return id;
	}
	
	public String getCompanyName(){
		return companyName;
	}
	
	public String getFirstName() {
		return firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public Date getBirthDate() {
		return birthDate;
	}

	public String getAddrStreet() {
		return addrStreet;
	}

	public String getAddrNumber() {
		return addrNumber;
	}

	public String getAddrPostCode() {
		return addrPostCode;
	}

	public String getAddrCity() {
		return addrCity;
	}

	public String getCountry() {
		return country;
	}
	
	public String getEmail() {
		return email;
	}
	
	public String getTelephone(){
		return telephone;
	}
	
	public Date getInscriptionDate(){
		return inscriptionDate;
	}
	
	public String getDeveloperSkills() {
		return developerSkills;
	}
	
	public String getDevelopperComment(){
		return developerComment;
	}
	
	public String getPassword(){
		return password;
	}
	
	// Setters
	public void setCompanyName(String companyName){
		this.companyName = companyName;
	}
	
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}

	public void setAddrStreet(String addrStreet) {
		this.addrStreet = addrStreet;
	}

	public void setAddrNumber(String addrNumber) {
		this.addrNumber = addrNumber;
	}

	public void setAddrPostCode(String addrPostCode) {
		this.addrPostCode = addrPostCode;
	}

	public void setAddrCity(String addrCity) {
		this.addrCity = addrCity;
	}

	public void setCountry(String country) {
		this.country = country;
	}
	
	public void setEmail(String email){
		this.email = email;
	}
	
	public void setTelephone(String telephone){
		this.telephone = telephone;
	}
	
	public void setInscriptionDate(Date inscriptionDate){
		this.inscriptionDate = inscriptionDate;
	}
	
	public void setDeveloperSkills(String developerSkills) {
		this.developerSkills = developerSkills;
	}
	
	public void setDeveloperComment(String developerComment){
		this.developerComment = developerComment;
	}
	
	public void setRole(Role role){
		this.role = role;
	}
	
	public void setPassword(String password){
		this.password = password;
	}
}